package com.medusa.aps.business.modules.modeling.model.input;

import com.medusa.aps.business.model.constant.RegexPool;
import com.medusa.aps.business.model.enums.EquipmentStatus;
import com.medusa.aps.business.model.enums.SourceEnum;
import com.medusa.aps.business.modules.modeling.mp.entity.Equipment;
import com.medusa.aps.business.common.web.valid.group.Update;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class EquipmentDTO {

    /**
     * id
     */
    @Schema(description = "主键")
    @NotNull(message = "id不能为空", groups = Update.class)
    private Long id;
    /**
     * 设备编码
     */
    @Schema(description = "设备编码")
    @Size(max = 50, message = "设备编码长度不能超过50")
    @NotBlank(message = "设备编码不能为空")
    @Pattern(regexp = RegexPool.ORDER_NO, message = "设备编码只支持数字、字母、符号")
    private String equipmentNumber;
    /**
     * 设备名称
     */
    @Schema(description = "设备名称")
    @Size(max = 50, message = "设备名称长度不能超过50")
    @NotBlank(message = "设备名称不能为空")
    private String deviceName;
    /**
     * 设备类型
     */
    @Schema(description = "设备类型")
    @Size(max = 50, message = "设备类型长度不能超过50")
    @NotBlank(message = "设备类型不能为空")
    private String deviceType;

    /**
     * 设备状态
     */
    @Schema(description = "设备状态")
    @NotNull(message = "设备状态不能为空")
    private EquipmentStatus equipmentStatus;
    /**
     * 所属车间id
     */
    @Schema(description = "所属车间id")
    @NotNull(message = "所属车间id不能为空")
    private Integer workshopId;

    /**
     * 所属车间
     */
    @Schema(description = "所属车间")
    private String workshopName;

    public Equipment newEquipment() {
        return new Equipment()
                .setId(id)
                .setEquipmentNumber(equipmentNumber)
                .setDeviceName(deviceName)
                .setDeviceType(deviceType)
                .setEquipmentStatus(equipmentStatus)
                .setWorkshopId(workshopId)
                .setDataSource(SourceEnum.ARTIFICIAL);
    }
}
